<template>
    <div class="goods-list">
        <div class="goods-item" v-for="item in goodslist" :key="item.id" @click="goGoodsinfo(item.id)">
            <img :src="item.img_url" alt="">
            <h1 class="title">{{ item.title }}</h1>
            <div class="info">
                <p class="price">
                    <span class="new-price">￥{{ item.sell_price }}</span>
                    <span class="old-price">￥{{ item.market_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.stock_quantity }}件</span>
                </p>
            </div>
        </div>
        <mt-button size="large" type="danger" @click="getGoodsmore">加载更多</mt-button>
    </div>
</template>

<script>
export default {
    data() {
        return {
            pagaindex:1,
            goodslist:[],
            id:this.$route.params.id
        }
    },
    created(){
        this.Getgoodslist()
    },
    methods: {
        // 获取商品列表
        Getgoodslist(){
            this.$axios.get('api/getgoods?pageindex='+this.pagaindex)
            .then(res=>{
                if(res.data.status === 0){
                    this.goodslist=this.goodslist.concat(res.data.message) 
                }
            })
        },
        // 加载更多
        getGoodsmore(){
            this.pagaindex++
            this.Getgoodslist()
        },
        // 编程式导航
        goGoodsinfo(id){
            this.$router.push('/home/goodsinfo/'+id)
        }
    },
    
}
</script>

<style scoped>
.goods-list{
    display: flex;
    padding: 7px;
    justify-content: space-between;
    flex-wrap: wrap;
}
.goods-item{
    flex-wrap: wrap;
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 8px #ccc;
    margin-top: 4px;
    margin-bottom: 4px;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 250px;
}
.goods-item img{
    width: 100%
}
.goods-item .title{
    font-size: 14px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
.goods-item .price .new-price{
    color: red;
    font-size: 16px;
    font-weight: 700
}
.goods-item .price .old-price{
    text-decoration: line-through;
    font-size: 12px;
    margin-left: 5px;
}
.info{
    background-color: #eee;
}
.info p{
    margin: 0;
    padding: 5px
}
.info .sell{
    display: flex;
    justify-content: space-between;
    font-size: 12px
}
</style>